<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Request;

class PersonalOthers extends OthersController
{
    public function index()
    {   
        
        //动态
        $odongtai = Db::field('u.icon,u.nickname,d.dtime,d.caozuo,d.use_id,d.id')
        ->table('bbs_user u, bbs_dongtai d')
        ->where('u.id = d.use_id')
        ->where('d.use_id',input('id'))
        ->order('dtime','desc')
        ->select();
        $this->assign('odongtai',$odongtai);

        //关注
        $oguanzhu = db('friend')->where('use_id',input('session.user.id'))->where('fid',input('id'))->select();
        if($oguanzhu){
        	$this->assign('oguanzhu', $oguanzhu);
        }

    	
        return view('personal_others/index');
    }



    public function addguanzhu()
    {   
        $data = ['use_id'=>input('session.user.id'),'fid'=>input('id')];
        $result = db('friend')->insert($data);
        if($result){
            db('blacklist')->where('use_id',input('session.user.id'))->where('hid',input('id'))->delete();
            return json($result);
        }
    }
 

     public function delguanzhu()
    {
        $result = db('friend')->where('use_id',input('session.user.id'))->where('fid',input('id'))->delete();
        return json($result);       
    }


    public function orizhi()
    {
        $orizhi = db('rizhi')->where('use_id',input('id'))->select();
        $this->assign('orizhi', $orizhi);

        return view('personal_others/orizhi');
    }


    public function readrizhi()
    {   
        Db::name('rizhi')
        ->where('id', input('rzid'))
        ->setInc('rz_read');

        $orizhiList = db('rizhi')->where('id',input('rzid'))->where('use_id',input('id'))->find();
        $this->assign('orizhiList', $orizhiList); 
        if(!$orizhiList){
            return view('404/404');
        }

        $orzreply = Db::query('select u.nickname,u.icon,r.use_id,r.rz_content,r.rz_time,r.id from bbs_user u,bbs_rz_reply r where r.rz_id='.input('rzid').' and r.use_id=u.id order by r.rz_time desc');
        $this->assign('orzreply', $orzreply); 

        return view('personal_others/oreadrizhi');
    }

    


}